import { defineStore } from 'pinia'
import { ref } from 'vue'

const initCardInfo = {
	name: '张明',
	title: '产品经理',
	company: '科技有限公司',
	phone: '13800138000',
	email: 'zhangming@example.com',
	address: '北京市朝阳区',
	avatar: 'https://picsum.photos/id/1005/200/200',
	qrcode: 'https://picsum.photos/id/237/100/100',
}

type CardInfo = {
	name : string
	title : string
	company : string
	phone : string
	email : string
	address : string
	avatar : string
	qrcode : string
}

export const cardStore = defineStore(
	'card',
	() => {
		const cardInfo = ref({ ...initCardInfo })
		const templateInfo = ref({
			 type: "default"			
		});
		// let selectedTemplate = 'default'
		const setTemplate = (template : string) => {
			console.log("*****template******")
			console.log(template)
			const obj={type: template}
			templateInfo.value = obj
		}
		const updateCardInfo = (info : CardInfo) => {
			cardInfo.value = { ...info }
		}
		return {
			cardInfo,
			// selectedTemplate,
			setTemplate,
			updateCardInfo,
			templateInfo,
		}
	},
	{
		// 如果需要持久化就写 true, 不需要持久化就写 false（或者去掉这个配置项）
		persist: true,
	},
)